// 简单的状态管理
const store = {
  state: {
    userInfo: uni.getStorageSync('userInfo') || null,
    cartList: uni.getStorageSync('cartList') || []
  },
  
  setUserInfo(userInfo) {
    this.state.userInfo = userInfo
    uni.setStorageSync('userInfo', userInfo)
  },
  
  addToCart(product) {
    const existingProduct = this.state.cartList.find(item => item.id === product.id)
    if (existingProduct) {
      existingProduct.quantity += 1
    } else {
      this.state.cartList.push({
        ...product,
        quantity: 1
      })
    }
    uni.setStorageSync('cartList', this.state.cartList)
  },
  
  getCartCount() {
    return this.state.cartList.reduce((total, item) => total + item.quantity, 0)
  }
}

export default store 